
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/19/2011 08:03:56
-- Generated from EDMX file: C:\Users\Alexis\Documents\Visual Studio 2010\Projects\DrivingCRM\DrivingCRM\DrivingCRM\Model\Model_DrivingCRM.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [DRIVINGCRM];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_EventEventInscription]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventInscriptionSet] DROP CONSTRAINT [FK_EventEventInscription];
GO
IF OBJECT_ID(N'[dbo].[FK_AddressClient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Client] DROP CONSTRAINT [FK_AddressClient];
GO
IF OBJECT_ID(N'[dbo].[FK_AgencyPlace]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PlaceSet] DROP CONSTRAINT [FK_AgencyPlace];
GO
IF OBJECT_ID(N'[dbo].[FK_AgencyVehicle]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VehicleSet] DROP CONSTRAINT [FK_AgencyVehicle];
GO
IF OBJECT_ID(N'[dbo].[FK_SalesmanBill]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BillSet] DROP CONSTRAINT [FK_SalesmanBill];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientBill]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BillSet] DROP CONSTRAINT [FK_ClientBill];
GO
IF OBJECT_ID(N'[dbo].[FK_AgencyStakeholder]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Stakeholder] DROP CONSTRAINT [FK_AgencyStakeholder];
GO
IF OBJECT_ID(N'[dbo].[FK_StakeholderEvent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventSet] DROP CONSTRAINT [FK_StakeholderEvent];
GO
IF OBJECT_ID(N'[dbo].[FK_AgencySalesman]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Salesman] DROP CONSTRAINT [FK_AgencySalesman];
GO
IF OBJECT_ID(N'[dbo].[FK_AgencyClient]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Client] DROP CONSTRAINT [FK_AgencyClient];
GO
IF OBJECT_ID(N'[dbo].[FK_DiscussionPost]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostSet] DROP CONSTRAINT [FK_DiscussionPost];
GO
IF OBJECT_ID(N'[dbo].[FK_PackageProduct]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProductSet] DROP CONSTRAINT [FK_PackageProduct];
GO
IF OBJECT_ID(N'[dbo].[FK_StreetTypeAddress]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AddressSet] DROP CONSTRAINT [FK_StreetTypeAddress];
GO
IF OBJECT_ID(N'[dbo].[FK_EventMark]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MarkSet] DROP CONSTRAINT [FK_EventMark];
GO
IF OBJECT_ID(N'[dbo].[FK_AgencyEvent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventSet] DROP CONSTRAINT [FK_AgencyEvent];
GO
IF OBJECT_ID(N'[dbo].[FK_PlaceTypePlace]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PlaceSet] DROP CONSTRAINT [FK_PlaceTypePlace];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientMark]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MarkSet] DROP CONSTRAINT [FK_ClientMark];
GO
IF OBJECT_ID(N'[dbo].[FK_UserDiscussion]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DiscussionSet] DROP CONSTRAINT [FK_UserDiscussion];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPost]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PostSet] DROP CONSTRAINT [FK_UserPost];
GO
IF OBJECT_ID(N'[dbo].[FK_AddressAgency]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AgencySet] DROP CONSTRAINT [FK_AddressAgency];
GO
IF OBJECT_ID(N'[dbo].[FK_BillBillItem]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BillItemSet] DROP CONSTRAINT [FK_BillBillItem];
GO
IF OBJECT_ID(N'[dbo].[FK_BillItemPackage]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BillItemSet] DROP CONSTRAINT [FK_BillItemPackage];
GO
IF OBJECT_ID(N'[dbo].[FK_BillItemProduct]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[BillItemSet] DROP CONSTRAINT [FK_BillItemProduct];
GO
IF OBJECT_ID(N'[dbo].[FK_ClientEventInscription]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EventInscriptionSet] DROP CONSTRAINT [FK_ClientEventInscription];
GO
IF OBJECT_ID(N'[dbo].[FK_AddressPlace]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PlaceSet] DROP CONSTRAINT [FK_AddressPlace];
GO
IF OBJECT_ID(N'[dbo].[FK_Client_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Client] DROP CONSTRAINT [FK_Client_inherits_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Salesman_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Salesman] DROP CONSTRAINT [FK_Salesman_inherits_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Stakeholder_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Stakeholder] DROP CONSTRAINT [FK_Stakeholder_inherits_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Car_inherits_Vehicle]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VehicleSet_Car] DROP CONSTRAINT [FK_Car_inherits_Vehicle];
GO
IF OBJECT_ID(N'[dbo].[FK_Motorcycle_inherits_Vehicle]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VehicleSet_Motorcycle] DROP CONSTRAINT [FK_Motorcycle_inherits_Vehicle];
GO
IF OBJECT_ID(N'[dbo].[FK_Administrator_inherits_User]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[UserSet_Administrator] DROP CONSTRAINT [FK_Administrator_inherits_User];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[AddressSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AddressSet];
GO
IF OBJECT_ID(N'[dbo].[AgencySet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AgencySet];
GO
IF OBJECT_ID(N'[dbo].[EventSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EventSet];
GO
IF OBJECT_ID(N'[dbo].[EventInscriptionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EventInscriptionSet];
GO
IF OBJECT_ID(N'[dbo].[LogSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LogSet];
GO
IF OBJECT_ID(N'[dbo].[MarkSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MarkSet];
GO
IF OBJECT_ID(N'[dbo].[PlaceSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PlaceSet];
GO
IF OBJECT_ID(N'[dbo].[VehicleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VehicleSet];
GO
IF OBJECT_ID(N'[dbo].[ProductSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProductSet];
GO
IF OBJECT_ID(N'[dbo].[PostSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PostSet];
GO
IF OBJECT_ID(N'[dbo].[DiscussionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DiscussionSet];
GO
IF OBJECT_ID(N'[dbo].[PackageSet1]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PackageSet1];
GO
IF OBJECT_ID(N'[dbo].[BillSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BillSet];
GO
IF OBJECT_ID(N'[dbo].[ArticleSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ArticleSet];
GO
IF OBJECT_ID(N'[dbo].[StreetTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[StreetTypeSet];
GO
IF OBJECT_ID(N'[dbo].[PlaceTypeSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PlaceTypeSet];
GO
IF OBJECT_ID(N'[dbo].[BillItemSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[BillItemSet];
GO
IF OBJECT_ID(N'[dbo].[UserSet_Client]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet_Client];
GO
IF OBJECT_ID(N'[dbo].[UserSet_Salesman]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet_Salesman];
GO
IF OBJECT_ID(N'[dbo].[UserSet_Stakeholder]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet_Stakeholder];
GO
IF OBJECT_ID(N'[dbo].[VehicleSet_Car]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VehicleSet_Car];
GO
IF OBJECT_ID(N'[dbo].[VehicleSet_Motorcycle]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VehicleSet_Motorcycle];
GO
IF OBJECT_ID(N'[dbo].[UserSet_Administrator]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet_Administrator];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] uniqueidentifier  NOT NULL,
    [Firstname] nvarchar(50)  NULL,
    [Lastname] nvarchar(50)  NULL,
    [Username] nvarchar(50)  NOT NULL,
    [Password] nvarchar(100)  NULL,
    [DateOfBirth] datetime  NULL,
    [Name] nvarchar(50)  NULL,
    [ApplicationName] nvarchar(100)  NULL,
    [CreationDate] datetime  NOT NULL,
    [Email] nvarchar(100)  NOT NULL,
    [PasswordQuestion] nvarchar(255)  NULL,
    [PasswordAnswer] nvarchar(255)  NULL,
    [IsApproved] bit  NOT NULL,
    [LastActivityDate] datetime  NULL,
    [LastLoginDate] datetime  NULL,
    [LastPasswordChangedDate] datetime  NULL,
    [IsOnline] bit  NULL,
    [IsLockedOut] bit  NULL,
    [LastLockedOutDate] datetime  NULL,
    [FailedPasswordAttemptCount] int  NULL,
    [FailedPasswordAttemptWindowStart] datetime  NULL,
    [FailedPasswordAnswerAttemptCount] int  NULL,
    [FailedPasswordAnswerAttemptWindowStart] datetime  NULL,
    [LastModified] datetime  NULL,
    [Comment] nvarchar(255)  NULL,
    [CompleteName] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'AddressSet'
CREATE TABLE [dbo].[AddressSet] (
    [IdAdress] int IDENTITY(1,1) NOT NULL,
    [Number] int  NOT NULL,
    [StreetName] nvarchar(max)  NOT NULL,
    [Extra] nvarchar(max)  NULL,
    [Zipcode] int  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [Cedex] int  NULL,
    [StreetTypeId] int  NOT NULL,
    [CompleteAddress] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'AgencySet'
CREATE TABLE [dbo].[AgencySet] (
    [IdAgency] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [AddressIdAdress] int  NOT NULL
);
GO

-- Creating table 'EventSet'
CREATE TABLE [dbo].[EventSet] (
    [IdEvent] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Duration] int  NOT NULL,
    [DateWithHour] datetime  NOT NULL,
    [StakeholderId] uniqueidentifier  NOT NULL,
    [AgencyIdAgency] int  NOT NULL,
    [EndDateWithHour] datetime  NOT NULL,
    [CompleteEvent] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'EventInscriptionSet'
CREATE TABLE [dbo].[EventInscriptionSet] (
    [IdEventInscription] int IDENTITY(1,1) NOT NULL,
    [InscriptionDate] datetime  NOT NULL,
    [InWait] bit  NOT NULL,
    [EventIdEvent] int  NOT NULL,
    [ClientId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'LogSet'
CREATE TABLE [dbo].[LogSet] (
    [IdLog] int IDENTITY(1,1) NOT NULL,
    [ErrorLevel] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [CreationDate] datetime  NOT NULL
);
GO

-- Creating table 'MarkSet'
CREATE TABLE [dbo].[MarkSet] (
    [IdMark] int IDENTITY(1,1) NOT NULL,
    [MarkingDate] datetime  NOT NULL,
    [Value] decimal(18,0)  NOT NULL,
    [EventIdEvent] int  NOT NULL,
    [ClientId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PlaceSet'
CREATE TABLE [dbo].[PlaceSet] (
    [IdPlace] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [AgencyIdAgency] int  NOT NULL,
    [PlaceTypeIdPlaceType] int  NOT NULL,
    [AddressIdAdress] int  NULL
);
GO

-- Creating table 'VehicleSet'
CREATE TABLE [dbo].[VehicleSet] (
    [IdVehicle] int IDENTITY(1,1) NOT NULL,
    [Brand] nvarchar(max)  NOT NULL,
    [Model] nvarchar(max)  NOT NULL,
    [Created_year] datetime  NOT NULL,
    [Licence] nvarchar(max)  NOT NULL,
    [LastRevisionDate] datetime  NOT NULL,
    [AgencyIdAgency] int  NOT NULL
);
GO

-- Creating table 'ProductSet'
CREATE TABLE [dbo].[ProductSet] (
    [IdProduct] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Price] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NULL,
    [PackageIdPackage] int  NULL
);
GO

-- Creating table 'PostSet'
CREATE TABLE [dbo].[PostSet] (
    [IdPost] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [DiscussionIdDiscussion] int  NOT NULL,
    [UserId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'DiscussionSet'
CREATE TABLE [dbo].[DiscussionSet] (
    [IdDiscussion] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [UserId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'PackageSet1'
CREATE TABLE [dbo].[PackageSet1] (
    [IdPackage] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [Price] decimal(18,0)  NOT NULL
);
GO

-- Creating table 'BillSet'
CREATE TABLE [dbo].[BillSet] (
    [IdBill] int IDENTITY(1,1) NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [Amount] decimal(18,0)  NOT NULL,
    [SalesmanId] uniqueidentifier  NOT NULL,
    [ClientId] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'ArticleSet'
CREATE TABLE [dbo].[ArticleSet] (
    [IdArticle] int IDENTITY(1,1) NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Content] nvarchar(max)  NOT NULL,
    [Category] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'StreetTypeSet'
CREATE TABLE [dbo].[StreetTypeSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'PlaceTypeSet'
CREATE TABLE [dbo].[PlaceTypeSet] (
    [IdPlaceType] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'BillItemSet'
CREATE TABLE [dbo].[BillItemSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Quantity] nvarchar(max)  NOT NULL,
    [Total] nvarchar(max)  NOT NULL,
    [BillIdBill] int  NOT NULL,
    [PackageIdPackage] int  NULL,
    [ProductIdProduct] int  NULL
);
GO

-- Creating table 'UserSet_Client'
CREATE TABLE [dbo].[UserSet_Client] (
    [TotalHours] int  NOT NULL,
    [RemainingHours] int  NOT NULL,
    [AgencyIdAgency] int  NOT NULL,
    [Id] uniqueidentifier  NOT NULL,
    [Address_IdAdress] int  NOT NULL
);
GO

-- Creating table 'UserSet_Salesman'
CREATE TABLE [dbo].[UserSet_Salesman] (
    [NumberSales] decimal(18,0)  NOT NULL,
    [AgencyIdAgency] int  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'UserSet_Stakeholder'
CREATE TABLE [dbo].[UserSet_Stakeholder] (
    [TeachMotorcycle] bit  NOT NULL,
    [TeachCar] bit  NOT NULL,
    [AgencyIdAgency] int  NOT NULL,
    [Id] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'VehicleSet_Car'
CREATE TABLE [dbo].[VehicleSet_Car] (
    [IdCar] int IDENTITY(1,1) NOT NULL,
    [Seating_number] int  NOT NULL,
    [IdVehicle] int  NOT NULL
);
GO

-- Creating table 'VehicleSet_Motorcycle'
CREATE TABLE [dbo].[VehicleSet_Motorcycle] (
    [IdMotorcycle] int IDENTITY(1,1) NOT NULL,
    [Capacity] int  NOT NULL,
    [IdVehicle] int  NOT NULL
);
GO

-- Creating table 'UserSet_Administrator'
CREATE TABLE [dbo].[UserSet_Administrator] (
    [Id] uniqueidentifier  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [IdAdress] in table 'AddressSet'
ALTER TABLE [dbo].[AddressSet]
ADD CONSTRAINT [PK_AddressSet]
    PRIMARY KEY CLUSTERED ([IdAdress] ASC);
GO

-- Creating primary key on [IdAgency] in table 'AgencySet'
ALTER TABLE [dbo].[AgencySet]
ADD CONSTRAINT [PK_AgencySet]
    PRIMARY KEY CLUSTERED ([IdAgency] ASC);
GO

-- Creating primary key on [IdEvent] in table 'EventSet'
ALTER TABLE [dbo].[EventSet]
ADD CONSTRAINT [PK_EventSet]
    PRIMARY KEY CLUSTERED ([IdEvent] ASC);
GO

-- Creating primary key on [IdEventInscription] in table 'EventInscriptionSet'
ALTER TABLE [dbo].[EventInscriptionSet]
ADD CONSTRAINT [PK_EventInscriptionSet]
    PRIMARY KEY CLUSTERED ([IdEventInscription] ASC);
GO

-- Creating primary key on [IdLog] in table 'LogSet'
ALTER TABLE [dbo].[LogSet]
ADD CONSTRAINT [PK_LogSet]
    PRIMARY KEY CLUSTERED ([IdLog] ASC);
GO

-- Creating primary key on [IdMark] in table 'MarkSet'
ALTER TABLE [dbo].[MarkSet]
ADD CONSTRAINT [PK_MarkSet]
    PRIMARY KEY CLUSTERED ([IdMark] ASC);
GO

-- Creating primary key on [IdPlace] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [PK_PlaceSet]
    PRIMARY KEY CLUSTERED ([IdPlace] ASC);
GO

-- Creating primary key on [IdVehicle] in table 'VehicleSet'
ALTER TABLE [dbo].[VehicleSet]
ADD CONSTRAINT [PK_VehicleSet]
    PRIMARY KEY CLUSTERED ([IdVehicle] ASC);
GO

-- Creating primary key on [IdProduct] in table 'ProductSet'
ALTER TABLE [dbo].[ProductSet]
ADD CONSTRAINT [PK_ProductSet]
    PRIMARY KEY CLUSTERED ([IdProduct] ASC);
GO

-- Creating primary key on [IdPost] in table 'PostSet'
ALTER TABLE [dbo].[PostSet]
ADD CONSTRAINT [PK_PostSet]
    PRIMARY KEY CLUSTERED ([IdPost] ASC);
GO

-- Creating primary key on [IdDiscussion] in table 'DiscussionSet'
ALTER TABLE [dbo].[DiscussionSet]
ADD CONSTRAINT [PK_DiscussionSet]
    PRIMARY KEY CLUSTERED ([IdDiscussion] ASC);
GO

-- Creating primary key on [IdPackage] in table 'PackageSet1'
ALTER TABLE [dbo].[PackageSet1]
ADD CONSTRAINT [PK_PackageSet1]
    PRIMARY KEY CLUSTERED ([IdPackage] ASC);
GO

-- Creating primary key on [IdBill] in table 'BillSet'
ALTER TABLE [dbo].[BillSet]
ADD CONSTRAINT [PK_BillSet]
    PRIMARY KEY CLUSTERED ([IdBill] ASC);
GO

-- Creating primary key on [IdArticle] in table 'ArticleSet'
ALTER TABLE [dbo].[ArticleSet]
ADD CONSTRAINT [PK_ArticleSet]
    PRIMARY KEY CLUSTERED ([IdArticle] ASC);
GO

-- Creating primary key on [Id] in table 'StreetTypeSet'
ALTER TABLE [dbo].[StreetTypeSet]
ADD CONSTRAINT [PK_StreetTypeSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [IdPlaceType] in table 'PlaceTypeSet'
ALTER TABLE [dbo].[PlaceTypeSet]
ADD CONSTRAINT [PK_PlaceTypeSet]
    PRIMARY KEY CLUSTERED ([IdPlaceType] ASC);
GO

-- Creating primary key on [Id] in table 'BillItemSet'
ALTER TABLE [dbo].[BillItemSet]
ADD CONSTRAINT [PK_BillItemSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet_Client'
ALTER TABLE [dbo].[UserSet_Client]
ADD CONSTRAINT [PK_UserSet_Client]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet_Salesman'
ALTER TABLE [dbo].[UserSet_Salesman]
ADD CONSTRAINT [PK_UserSet_Salesman]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet_Stakeholder'
ALTER TABLE [dbo].[UserSet_Stakeholder]
ADD CONSTRAINT [PK_UserSet_Stakeholder]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [IdVehicle] in table 'VehicleSet_Car'
ALTER TABLE [dbo].[VehicleSet_Car]
ADD CONSTRAINT [PK_VehicleSet_Car]
    PRIMARY KEY CLUSTERED ([IdVehicle] ASC);
GO

-- Creating primary key on [IdVehicle] in table 'VehicleSet_Motorcycle'
ALTER TABLE [dbo].[VehicleSet_Motorcycle]
ADD CONSTRAINT [PK_VehicleSet_Motorcycle]
    PRIMARY KEY CLUSTERED ([IdVehicle] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet_Administrator'
ALTER TABLE [dbo].[UserSet_Administrator]
ADD CONSTRAINT [PK_UserSet_Administrator]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [EventIdEvent] in table 'EventInscriptionSet'
ALTER TABLE [dbo].[EventInscriptionSet]
ADD CONSTRAINT [FK_EventEventInscription]
    FOREIGN KEY ([EventIdEvent])
    REFERENCES [dbo].[EventSet]
        ([IdEvent])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventEventInscription'
CREATE INDEX [IX_FK_EventEventInscription]
ON [dbo].[EventInscriptionSet]
    ([EventIdEvent]);
GO

-- Creating foreign key on [Address_IdAdress] in table 'UserSet_Client'
ALTER TABLE [dbo].[UserSet_Client]
ADD CONSTRAINT [FK_AddressClient]
    FOREIGN KEY ([Address_IdAdress])
    REFERENCES [dbo].[AddressSet]
        ([IdAdress])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressClient'
CREATE INDEX [IX_FK_AddressClient]
ON [dbo].[UserSet_Client]
    ([Address_IdAdress]);
GO

-- Creating foreign key on [AgencyIdAgency] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [FK_AgencyPlace]
    FOREIGN KEY ([AgencyIdAgency])
    REFERENCES [dbo].[AgencySet]
        ([IdAgency])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgencyPlace'
CREATE INDEX [IX_FK_AgencyPlace]
ON [dbo].[PlaceSet]
    ([AgencyIdAgency]);
GO

-- Creating foreign key on [AgencyIdAgency] in table 'VehicleSet'
ALTER TABLE [dbo].[VehicleSet]
ADD CONSTRAINT [FK_AgencyVehicle]
    FOREIGN KEY ([AgencyIdAgency])
    REFERENCES [dbo].[AgencySet]
        ([IdAgency])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgencyVehicle'
CREATE INDEX [IX_FK_AgencyVehicle]
ON [dbo].[VehicleSet]
    ([AgencyIdAgency]);
GO

-- Creating foreign key on [SalesmanId] in table 'BillSet'
ALTER TABLE [dbo].[BillSet]
ADD CONSTRAINT [FK_SalesmanBill]
    FOREIGN KEY ([SalesmanId])
    REFERENCES [dbo].[UserSet_Salesman]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SalesmanBill'
CREATE INDEX [IX_FK_SalesmanBill]
ON [dbo].[BillSet]
    ([SalesmanId]);
GO

-- Creating foreign key on [ClientId] in table 'BillSet'
ALTER TABLE [dbo].[BillSet]
ADD CONSTRAINT [FK_ClientBill]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[UserSet_Client]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientBill'
CREATE INDEX [IX_FK_ClientBill]
ON [dbo].[BillSet]
    ([ClientId]);
GO

-- Creating foreign key on [AgencyIdAgency] in table 'UserSet_Stakeholder'
ALTER TABLE [dbo].[UserSet_Stakeholder]
ADD CONSTRAINT [FK_AgencyStakeholder]
    FOREIGN KEY ([AgencyIdAgency])
    REFERENCES [dbo].[AgencySet]
        ([IdAgency])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgencyStakeholder'
CREATE INDEX [IX_FK_AgencyStakeholder]
ON [dbo].[UserSet_Stakeholder]
    ([AgencyIdAgency]);
GO

-- Creating foreign key on [StakeholderId] in table 'EventSet'
ALTER TABLE [dbo].[EventSet]
ADD CONSTRAINT [FK_StakeholderEvent]
    FOREIGN KEY ([StakeholderId])
    REFERENCES [dbo].[UserSet_Stakeholder]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StakeholderEvent'
CREATE INDEX [IX_FK_StakeholderEvent]
ON [dbo].[EventSet]
    ([StakeholderId]);
GO

-- Creating foreign key on [AgencyIdAgency] in table 'UserSet_Salesman'
ALTER TABLE [dbo].[UserSet_Salesman]
ADD CONSTRAINT [FK_AgencySalesman]
    FOREIGN KEY ([AgencyIdAgency])
    REFERENCES [dbo].[AgencySet]
        ([IdAgency])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgencySalesman'
CREATE INDEX [IX_FK_AgencySalesman]
ON [dbo].[UserSet_Salesman]
    ([AgencyIdAgency]);
GO

-- Creating foreign key on [AgencyIdAgency] in table 'UserSet_Client'
ALTER TABLE [dbo].[UserSet_Client]
ADD CONSTRAINT [FK_AgencyClient]
    FOREIGN KEY ([AgencyIdAgency])
    REFERENCES [dbo].[AgencySet]
        ([IdAgency])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgencyClient'
CREATE INDEX [IX_FK_AgencyClient]
ON [dbo].[UserSet_Client]
    ([AgencyIdAgency]);
GO

-- Creating foreign key on [DiscussionIdDiscussion] in table 'PostSet'
ALTER TABLE [dbo].[PostSet]
ADD CONSTRAINT [FK_DiscussionPost]
    FOREIGN KEY ([DiscussionIdDiscussion])
    REFERENCES [dbo].[DiscussionSet]
        ([IdDiscussion])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_DiscussionPost'
CREATE INDEX [IX_FK_DiscussionPost]
ON [dbo].[PostSet]
    ([DiscussionIdDiscussion]);
GO

-- Creating foreign key on [PackageIdPackage] in table 'ProductSet'
ALTER TABLE [dbo].[ProductSet]
ADD CONSTRAINT [FK_PackageProduct]
    FOREIGN KEY ([PackageIdPackage])
    REFERENCES [dbo].[PackageSet1]
        ([IdPackage])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PackageProduct'
CREATE INDEX [IX_FK_PackageProduct]
ON [dbo].[ProductSet]
    ([PackageIdPackage]);
GO

-- Creating foreign key on [StreetTypeId] in table 'AddressSet'
ALTER TABLE [dbo].[AddressSet]
ADD CONSTRAINT [FK_StreetTypeAddress]
    FOREIGN KEY ([StreetTypeId])
    REFERENCES [dbo].[StreetTypeSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_StreetTypeAddress'
CREATE INDEX [IX_FK_StreetTypeAddress]
ON [dbo].[AddressSet]
    ([StreetTypeId]);
GO

-- Creating foreign key on [EventIdEvent] in table 'MarkSet'
ALTER TABLE [dbo].[MarkSet]
ADD CONSTRAINT [FK_EventMark]
    FOREIGN KEY ([EventIdEvent])
    REFERENCES [dbo].[EventSet]
        ([IdEvent])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EventMark'
CREATE INDEX [IX_FK_EventMark]
ON [dbo].[MarkSet]
    ([EventIdEvent]);
GO

-- Creating foreign key on [AgencyIdAgency] in table 'EventSet'
ALTER TABLE [dbo].[EventSet]
ADD CONSTRAINT [FK_AgencyEvent]
    FOREIGN KEY ([AgencyIdAgency])
    REFERENCES [dbo].[AgencySet]
        ([IdAgency])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AgencyEvent'
CREATE INDEX [IX_FK_AgencyEvent]
ON [dbo].[EventSet]
    ([AgencyIdAgency]);
GO

-- Creating foreign key on [PlaceTypeIdPlaceType] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [FK_PlaceTypePlace]
    FOREIGN KEY ([PlaceTypeIdPlaceType])
    REFERENCES [dbo].[PlaceTypeSet]
        ([IdPlaceType])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PlaceTypePlace'
CREATE INDEX [IX_FK_PlaceTypePlace]
ON [dbo].[PlaceSet]
    ([PlaceTypeIdPlaceType]);
GO

-- Creating foreign key on [ClientId] in table 'MarkSet'
ALTER TABLE [dbo].[MarkSet]
ADD CONSTRAINT [FK_ClientMark]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[UserSet_Client]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientMark'
CREATE INDEX [IX_FK_ClientMark]
ON [dbo].[MarkSet]
    ([ClientId]);
GO

-- Creating foreign key on [UserId] in table 'DiscussionSet'
ALTER TABLE [dbo].[DiscussionSet]
ADD CONSTRAINT [FK_UserDiscussion]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserDiscussion'
CREATE INDEX [IX_FK_UserDiscussion]
ON [dbo].[DiscussionSet]
    ([UserId]);
GO

-- Creating foreign key on [UserId] in table 'PostSet'
ALTER TABLE [dbo].[PostSet]
ADD CONSTRAINT [FK_UserPost]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserPost'
CREATE INDEX [IX_FK_UserPost]
ON [dbo].[PostSet]
    ([UserId]);
GO

-- Creating foreign key on [AddressIdAdress] in table 'AgencySet'
ALTER TABLE [dbo].[AgencySet]
ADD CONSTRAINT [FK_AddressAgency]
    FOREIGN KEY ([AddressIdAdress])
    REFERENCES [dbo].[AddressSet]
        ([IdAdress])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressAgency'
CREATE INDEX [IX_FK_AddressAgency]
ON [dbo].[AgencySet]
    ([AddressIdAdress]);
GO

-- Creating foreign key on [BillIdBill] in table 'BillItemSet'
ALTER TABLE [dbo].[BillItemSet]
ADD CONSTRAINT [FK_BillBillItem]
    FOREIGN KEY ([BillIdBill])
    REFERENCES [dbo].[BillSet]
        ([IdBill])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillBillItem'
CREATE INDEX [IX_FK_BillBillItem]
ON [dbo].[BillItemSet]
    ([BillIdBill]);
GO

-- Creating foreign key on [PackageIdPackage] in table 'BillItemSet'
ALTER TABLE [dbo].[BillItemSet]
ADD CONSTRAINT [FK_BillItemPackage]
    FOREIGN KEY ([PackageIdPackage])
    REFERENCES [dbo].[PackageSet1]
        ([IdPackage])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillItemPackage'
CREATE INDEX [IX_FK_BillItemPackage]
ON [dbo].[BillItemSet]
    ([PackageIdPackage]);
GO

-- Creating foreign key on [ProductIdProduct] in table 'BillItemSet'
ALTER TABLE [dbo].[BillItemSet]
ADD CONSTRAINT [FK_BillItemProduct]
    FOREIGN KEY ([ProductIdProduct])
    REFERENCES [dbo].[ProductSet]
        ([IdProduct])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BillItemProduct'
CREATE INDEX [IX_FK_BillItemProduct]
ON [dbo].[BillItemSet]
    ([ProductIdProduct]);
GO

-- Creating foreign key on [ClientId] in table 'EventInscriptionSet'
ALTER TABLE [dbo].[EventInscriptionSet]
ADD CONSTRAINT [FK_ClientEventInscription]
    FOREIGN KEY ([ClientId])
    REFERENCES [dbo].[UserSet_Client]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ClientEventInscription'
CREATE INDEX [IX_FK_ClientEventInscription]
ON [dbo].[EventInscriptionSet]
    ([ClientId]);
GO

-- Creating foreign key on [AddressIdAdress] in table 'PlaceSet'
ALTER TABLE [dbo].[PlaceSet]
ADD CONSTRAINT [FK_AddressPlace]
    FOREIGN KEY ([AddressIdAdress])
    REFERENCES [dbo].[AddressSet]
        ([IdAdress])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AddressPlace'
CREATE INDEX [IX_FK_AddressPlace]
ON [dbo].[PlaceSet]
    ([AddressIdAdress]);
GO

-- Creating foreign key on [Id] in table 'UserSet_Client'
ALTER TABLE [dbo].[UserSet_Client]
ADD CONSTRAINT [FK_Client_inherits_User]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'UserSet_Salesman'
ALTER TABLE [dbo].[UserSet_Salesman]
ADD CONSTRAINT [FK_Salesman_inherits_User]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'UserSet_Stakeholder'
ALTER TABLE [dbo].[UserSet_Stakeholder]
ADD CONSTRAINT [FK_Stakeholder_inherits_User]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [IdVehicle] in table 'VehicleSet_Car'
ALTER TABLE [dbo].[VehicleSet_Car]
ADD CONSTRAINT [FK_Car_inherits_Vehicle]
    FOREIGN KEY ([IdVehicle])
    REFERENCES [dbo].[VehicleSet]
        ([IdVehicle])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [IdVehicle] in table 'VehicleSet_Motorcycle'
ALTER TABLE [dbo].[VehicleSet_Motorcycle]
ADD CONSTRAINT [FK_Motorcycle_inherits_Vehicle]
    FOREIGN KEY ([IdVehicle])
    REFERENCES [dbo].[VehicleSet]
        ([IdVehicle])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Id] in table 'UserSet_Administrator'
ALTER TABLE [dbo].[UserSet_Administrator]
ADD CONSTRAINT [FK_Administrator_inherits_User]
    FOREIGN KEY ([Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------